Skip to content

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Aug 8, 2025

Manual gensym code often contains a lot of mistakes, either because the
user uses something like . or +, or because it combines code from
multiple modules (gensym is only unique within a pre-compile unit). This
replaces most uses for macro local variables with proper scope markers.
I did not rewrite _lift_one_interp_helper or replace_ref_begin_end_
however, since, while possible by adding esc to every argument that
has not used a gensym value, if any other argument did is a value, I
worried that could lead to macroexpand.scm making more new mistakes so I
left if for a separate PR. Better yet, we could make a unhygienic-scope
and unescape pair for marking the inverse/dual of the usual operations
(marking a symbol as unescaped within a region of unhygienic (escaped)
code to make these various uses easier to implement.

But also do rewrite replace_ref_begin_end_ to respect argument order
and evaluation count (similar to its julia-syntax.scm counterpart) and
scoping (not adding let unpredictably).

@vtjnash vtjnash changed the title Rewrite most gensym macros to use automatic hygiene instead [NFCI] Rewrite most gensym macros to use automatic hygiene instead Aug 8, 2025
@vtjnash vtjnash added compiler:lowering Syntax lowering (compiler front end, 2nd stage) macros @macros labels Aug 8, 2025
@vtjnash vtjnash force-pushed the jn/gensym-deprecated branch from 4cf81b5 to c244cf7 Compare August 8, 2025 21:19
Allows using meta.jl much earlier in the build (instead of importing
these from show.jl).
@vtjnash vtjnash force-pushed the jn/gensym-deprecated branch from c244cf7 to 2dc46a2 Compare August 14, 2025 13:41
Manual `gensym` code often contains a lot of mistakes, either because
the user uses something like `.` or `+`, or because it combines code
from multiple modules (gensym is only unique within a pre-compile unit).
This replaces most uses for macro local variables with proper scope
markers, and checks for those markers correctly when doing replacements.
I did not fully rewrite `_lift_one_interp_helper` or
`replace_ref_begin_end_` however, since, while possible by adding `esc`
to every argument that has not used a gensym value, if any other
argument did is a value, I worried that could lead to macroexpand.scm
making more new mistakes so I left if for a separate PR. Better yet, we
could make a unhygienic-scope and unescape pair for marking the
inverse/dual of the usual operations (marking a symbol as unescaped
within a region of unhygienic (escaped) code to make these various uses
easier to implement.

But rewrite `replace_ref_begin_end_` to respect argument order and
evaluation count (similar to its julia-syntax.scm counterpart) and
scoping (not adding `let` unpredictably). This required also rewriting
`gen_call_with_extracted_types` to properly support the ways that
might require rewriting the expression, particularly against the new
`::` syntax support in the interactive macros.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:lowering Syntax lowering (compiler front end, 2nd stage) macros @macros
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant